<template>
    <el-form ref="basePrinterDialogForm" :rules="rules" :model="formData" label-width="100px">
        <el-form-item label="打印机SN" prop="code">
            <el-input v-model="formData.code" autocomplete="off" type="text"
                      placeholder="打印机SN" />
        </el-form-item>
        <el-form-item label="打印机名称" prop="name">
            <el-input v-model="formData.name" autocomplete="off" type="text"
                      placeholder="请输入打印机名称" />
        </el-form-item>
        <el-form-item label="打印机品牌" prop="brand">
            <el-select v-model="formData.brand" style="width: 100%;">
                <el-option value="xpyun" label="芯烨云" />
            </el-select>
        </el-form-item>
        <el-form-item label="排序" prop="sn">
            <el-input v-model="formData.sn" autocomplete="off" type="number"
                      placeholder="请输入排序序号" v-int />
        </el-form-item>
    </el-form>
</template>

<script>
import base from "@common/components/dialog/base.js";

export default {
    extends: base,
    name: "YunPrinterDialog",
    data() {
        return {
            rules: {
                code: [ { required: true, message: '请输入打印机SN', trigger: 'blur' } ],
                name: [ { required: true, message: '请输入名称', trigger: 'blur' } ],
                brand: [ { required: true, message: '请选择品牌', trigger: 'blur' } ],
            },
            formData: {},
        };
    },
    methods: {
        init() {
            const _this = this;
            if (_this.propsData.init) {
                return;
            }
            if (_this.$refs.basePrinterDialogForm) {
                _this.$refs.basePrinterDialogForm.clearValidate();
            }
            _this.formData = $.extend({}, _this.propsData.row);
        },
        async confirm() {
            let _this = this;
            let valid = await _this.validateForm('basePrinterDialogForm');
            if (valid) {
                let subData = $.extend({}, _this.formData);
                return _this.fetchData(_this.$api.API_SaveBasePrinter, subData).then(() => {
                    _this.$message.success('保存成功！');
                    return true;
                }).catch(() => {
                    return false;
                });
            }
            return valid;
        },
    },
}
</script>

<style lang="less" rel="stylesheet/less" scoped>
.dining_table_dialog_container {
    width: 100%;
    height: 100%;
}
</style>
